<template>
  <div class="app-container">
    <div class="table">
      <el-form
        :model="queryParams"
        ref="queryForm"
        size="small"
        :inline="true"
        v-show="showSearch"
        label-width="88px"
      >
        <el-form-item label="" prop="productName">
          <el-input
            v-model="queryParams.productName"
            placeholder="请输入商品名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="userId">
          <el-input
            @input="
              (value) => (this.queryParams.userId = value.replace(/[^\d]/g, ''))
            "
            v-model="queryParams.userId"
            placeholder="请输入会员ID"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item label="" prop="date">
          <el-date-picker
            v-model="queryParams.date"
            type="date"
            placeholder="请选择日期"
            clearable
            :editable="false"
            value-format="yyyy-MM-dd"
            @keyup.enter.native="handleQuery"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
            >重置</el-button
          >
        </el-form-item>
      </el-form>

      <!-- <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['system:good:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
                    v-hasPermi="['system:good:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                    @click="handleDelete" v-hasPermi="['system:good:remove']">删除</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                    v-hasPermi="['system:good:export']">批量导出</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row> -->

      <el-table v-loading="loading" :data="goodList">
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column
          label="会员ID"
          align="center"
          prop="userId"
          width="100"
        />
        <el-table-column label="会员" prop="deptName">
          <template slot-scope="{ row }">
            <div class="user-box">
              <image-preview
                :src="row.userAvatar"
                width="50px"
                height="50px"
                style="margin-right: 10px"
              ></image-preview>
              <div>
                <div>{{ row.userName }}</div>
                <div>{{ row.userPhoneNumber }}</div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="商品" prop="deptName" show-overflow-tooltip>
          <template slot-scope="{ row }">
            <div class="user-box">
              <image-preview
                :src="row.productImage"
                width="50px"
                height="50px"
                style="margin-right: 10px"
              ></image-preview>
              <div>
                <div>{{ row.productName }}</div>
                <div style="color: red">
                  <span>积分{{ row.points }}</span
                  ><span v-if="row.price"> + ￥{{ row.price }}</span>
                </div>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="订单编号" align="center" prop="orderNumber" />
        <el-table-column label="兑换数量" align="center" prop="productQuantity">
        </el-table-column>
        <el-table-column label="创建时间" align="center" prop="createTime">
        </el-table-column>
        <el-table-column width="180" label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="orderDetail(scope.row)"
              v-hasPermi="['system:good:edit']"
              >订单详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </div>
  </div>
</template>

<script>
import { pointExchangeRecord } from "@/api/pointsMall/record";

export default {
  name: "Good",
  data() {
    return {
      checkboxList: "",
      activeName: "first",
      // 日期范围
      dateRange: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应商商品表格数据
      goodList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodId: null,
        userId: null,
        deptName: null,
        sort: null,
        classifyImg: null,
        status: null,
        delFlag: null,
        dataTime: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        productLevel: [
          {
            required: true,
            message: "商品等级 1vip 3共享店主 4联创 5区域运营 6总裁不能为空",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 积分商城兑换记录 */
    getList() {
      this.loading = true;
      pointExchangeRecord(this.queryParams).then((response) => {
        this.goodList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    /**订单详情 */
    orderDetail(row) {
      this.$router.push(`/order/manage/detail?id=${row.orderNumber}`);
      // window.open(`/order/manage/detail?id=${row.orderNumber}`);
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        deptName: null,
        sort: null,
        classifyImg: null,
        status: null,
        delFlag: null,
      };
      this.dateRange = [];
      this.resetForm("form");
    },
    uploadImg(v) {
      this.form.classifyImg = v;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加商品分类";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      goodClassifyDetail(id).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改商品分类";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.status = this.form.status ? "0" : "1";
          this.form.delFlag = this.form.delFlag ? "0" : "1";
          if (this.form.id != null) {
            goodclassifyEdit(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            goodclassifyAdd(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm("是否确认删除数据？")
        .then(function () {
          return goodclassifyDelete(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "system/good/export",
        {
          ...this.queryParams,
        },
        `good_${new Date().getTime()}.xlsx`
      );
    },
  },
};
</script>
<style lang="less" scoped>
.app-container {
  width: 100%;
  height: 1005;
  background-color: #f8f8f8;

  .order_stat {
    background: #fff;
    padding: 10px 10px;
    margin-bottom: 10px;

    .title {
      font-size: 18px;
      font-weight: bold;
      display: flex;
      align-items: center;
      height: 40px;
      display: flex;
      justify-content: space-between;
    }
  }

  .table {
    width: 100%;
    background-color: #fff;
    padding: 15px 10px;
  }
}
.user-box {
  display: flex;
  align-items: center;
}
</style>
